package cn.wen.yinxiu.system.controller;

import java.util.Arrays;
import java.util.Map;

import cn.wen.yinxiu.common.convention.result.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import cn.wen.yinxiu.system.entity.AdvertEntity;
import cn.wen.yinxiu.system.service.AdvertService;
import cn.wen.yinxiu.common.toolkit.PageUtils;
import cn.wen.yinxiu.common.convention.result.ResultEntity;
import org.springframework.web.multipart.MultipartFile;

/**
 *
 * @ClassName: AdvertController
 * @Author 小飞
 * @Email coderwen22@163.com
 * @Date 2023-05-22 09:46:50
 * @Description: 的Controller层
 */
@RestController
@RequestMapping("/web")
public class AdvertController {

    @Autowired
    private AdvertService advertService;

    @PostMapping("/api/system/advert/save")
    public ResultEntity saveWorksAdvertInfo(@RequestPart("imageList")MultipartFile[] imageList,
                                            @RequestParam("advertInfoJSON") String advertInfoJSON) {
        boolean res = advertService.saveWorksAdvertInfo(imageList, advertInfoJSON);
        if (!res) return Results.failure();
        return Results.success();
    }

    @PostMapping("/api/system/advert/delete")
    public ResultEntity saveWorksAdvertInfo(@RequestParam("worksId") Long worksId,
                                            @RequestParam("advertId") Long advertId) {
        boolean res = advertService.deleteWorksAdvertInfo(worksId, advertId);
        if (!res) return Results.failure();
        return Results.success();
    }

    @PostMapping("/api/system/advert/update")
    public ResultEntity updateWorksAdvertInfo(@RequestPart("imageList")MultipartFile[] imageList,
                                            @RequestParam("advertInfoJSON") String advertInfoJSON) {
        boolean res = advertService.updateWorksAdvertInfo(imageList, advertInfoJSON);
        if (!res) return Results.failure();
        return Results.success();
    }

}
